<style>
#AddFolderButton{
	margin-left: 20px;
}
#AddFolderTable td{
	padding-top: 16px;
}
#AddFolderTable input{
	padding: 4px;
}
#LoginMessageTd{
	height: 48px;
	display: none;
	color: #D44;
}
#NoteFooterTd{
	color: #BBB;
}
</style>

<table class='FrameTable' id='AddFolderTable'>
	<tr><td><v-text id='FolderText' title='目录名称' maxlength='16' size='14'></v-text></td></tr>
	<tr><td><v-icon title='目标图标' path='menu' id='FolderIcon'></v-icon><v-button id='AddFolderButton' title='添加'></v-button></td></tr>
	<tr><td id='LoginMessageTd'>登录后才能使用笔记&nbsp;<a class='TextLink' href='javascript:void(0)'>马上登录</a></td></tr>
	<tr><td id='NoteFooterTd'>大道至简，笔记简单就很好。</td></tr>
</table>

<script>
getVue('AddFolderTable');

$('#FolderIcon').css('background-image', 'url(/res/img/menu/folder.png)');

if (isTimeout()){
	$('#LoginMessageTd').show();
	$('#FolderText').focus(sessionTimeout);
	$('#AddFolderButton').click(sessionTimeout);
	$('#LoginMessageTd a').click(sessionTimeout);
}
else{
	$('#FolderText').focus();

	$('#AddFolderButton').click(function(){
		var folder = $('#FolderText').val();
		var icon = getBackgroundImage(getCtrl('FolderIcon'));
		
		if ((len = strlen(folder)) == 0){
			showToast('请输入目录名称');
			$('#FolderText').focus();
		}
		else if (len > 16){
			showToast('目录名称最多8个汉字或16个英文字母');
			$('#FolderText').focus();
		}
		else if (!isFileName(folder)){
			showToast('目录名称不能包含特殊字符');
			$('#FolderText').focus();
		}
		else if (hasSubmenu(folder) || folder.toUpperCase() == 'WEBPAGE'){
			showToast('目录名称与现有目录冲突');
			$('#FolderText').focus();
		}
		else{
			var param = {};
			param['flag'] = 'C';
			param['icon'] = getString(icon);
			param['folder'] = getString(folder);

			getHttpResult('/editnote', param, function(data){
				if (data.code == XG_TIMEOUT){
					sessionTimeout();
				}
				else if (data.code == XG_AUTHFAIL){
					showNoAccessToast();
				}
				else if (data.code < 0){
					showToast('添加笔记分类失败');
				}
				else{
					updateSubmenu();
				}
			});
		}
	});
}

</script>
